package com.huadi.firematerialident.service;

import com.huadi.firematerialident.dao.FireMaterialEvidenceInfoDaoImpl;
import com.huadi.firematerialident.po.FireMaterialEvidenceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class FireMaterialEvidenceInfoServiceImpl implements FireMaterialEvidenceInfoService{
    @Autowired
    FireMaterialEvidenceInfoDaoImpl firematerialevidenceinfoDao;

    @Override
    public int addFireMaterialEvidenceInfo(FireMaterialEvidenceInfo firematerialevidenceinfo) {
        return firematerialevidenceinfoDao.addFireMaterialEvidenceInfo(firematerialevidenceinfo);
    }

    @Override
    public int deleteFireMaterialEvidenceInfoByID(String meID) {
        return firematerialevidenceinfoDao.deleteFireMaterialEvidenceInfoByID(meID);
    }

    @Override
    public int updateFireMaterialEvidenceInfo(FireMaterialEvidenceInfo firematerialevidenceinfo) {
        return firematerialevidenceinfoDao.updateFireMaterialEvidenceInfo(firematerialevidenceinfo);
    }

    @Override
    public List<Map<String,Object>> selectFireMaterialEvidenceInfoByID(String meID) {
        return firematerialevidenceinfoDao.selectFireMaterialEvidenceInfoByID(meID);
    }

    @Override
    public List<Map<String,Object>> getAllFireMaterialEvidenceInfo() {
        return firematerialevidenceinfoDao.getAllFireMaterialEvidenceInfo();
    }

    @Override
    public FireMaterialEvidenceInfo selectFireMaterialEvidenceInfoByID_class(String id) {
        List<Map<String ,Object>> list = firematerialevidenceinfoDao.selectFireMaterialEvidenceInfoByID(id);
        FireMaterialEvidenceInfo finfo = new FireMaterialEvidenceInfo();
        finfo.setMEID((String) list.get(0).get("MEID"));
        finfo.setFireInfoID((String) list.get(0).get("FireInfoID"));
        finfo.setMEType((String) list.get(0).get("METype"));
        finfo.setMoreInfo((String) list.get(0).get("MoreInfo"));
        finfo.setArchivingStatus((String) list.get(0).get("ArchivingStatus"));
        finfo.setLogicalAddDel((boolean) list.get(0).get("LogicalAddDel"));
        finfo.setLastModification((LocalDateTime) list.get(0).get("LastModification"));
        return finfo;
    }

    //判断物证在信息库中是否存在，存在返回1，不存在返回0
    @Override
    public int  JudgeMaterial(String id){
        List<Map<String ,Object>> list = firematerialevidenceinfoDao.selectFireMaterialEvidenceInfoByID(id);
        if(list.size()==0){
            return 0;
        }

        return 1;
    }
}
